package com.mofofa.maozy.repay.naira

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.mofofa.maozy.R
import com.mofofa.maozy.components.bill.BankAccountBill
import com.mofofa.maozy.data.RevObjPaystackCardListNgn

class PaystackCardNgnAdapter(private val dataList: List<RevObjPaystackCardListNgn>) :
    RecyclerView.Adapter<PaystackCardNgnAdapter.ViewHolder>() {

    private var mMaozyOnMaozyItemMaozyClickMaozyListener: (Int, RevObjPaystackCardListNgn) -> Unit =
        { positon, card -> }

    inner class ViewHolder(view: View, viewType: Int) : RecyclerView.ViewHolder(view) {
        var adpterBankAccountBill: BankAccountBill =
            view.findViewById(R.id.adpterBillTableBankAccount)
    }

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int,
    ): ViewHolder {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.view_maozy_adpter_select_account, parent, false)
        return ViewHolder(view, viewType)
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val data: RevObjPaystackCardListNgn = dataList[position]
        holder.adpterBankAccountBill.setMaozyAccountMaozyNumber(data.cardno)
        holder.adpterBankAccountBill.setMaozyAccountMaozyTitle(data.bankName.toString())
        holder.adpterBankAccountBill.setOnClickListener {
            mMaozyOnMaozyItemMaozyClickMaozyListener.invoke(position, data)
        }
    }

    override fun getItemCount(): Int {
        return dataList.size
    }

    fun setMaozyOnMaozyItemMaozyClickMaozyListener(listener: (Int, RevObjPaystackCardListNgn) -> Unit) {
        mMaozyOnMaozyItemMaozyClickMaozyListener = listener
    }
}